﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Drawing;

namespace WebApplication2.student
{
    public partial class 课程查询 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["xh"] != null)
            {
                if (!IsPostBack)
                {
                    bind();
                }
            }
            
             
        }
        private void bind()
        {
            string xh = "";
            xh = Session["xh"].ToString();
            string sql = "select kc.kcdm,kcmc,xf,dd,xm,dm,kclx from kc,kc_xs,ls where kc.kcdm=kc_xs.kcdm and kc.id_ls=ls.id and xh='001'";
            Database db = new Database();
            DataTable dt = db.SelectSQL(sql);

            DataList1.DataSource = dt;
            DataList1.DataBind();
        }

        protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            if(e.Item.ItemType==ListItemType.Item|| e.Item.ItemType == ListItemType.AlternatingItem)
            {
                string kclx = ((DataRowView)e.Item.DataItem).Row["kclx"].ToString().Trim();
                if(kclx=="必选课")
                {
                    Label lbl_kcdm = (Label)e.Item.FindControl("lbl_kcmc");
                    lbl_kcdm.ForeColor = Color.Red;
                }
                else
                {
                    Label lbl_kcdm = (Label)e.Item.FindControl("lbl_kcmc");
                    lbl_kcdm.ForeColor = Color.Black;
                }
                int xf = Convert.ToInt32(((DataRowView)e.Item.DataItem).Row["xf"].ToString().Trim());
                if(xf>5)
                {
                    Label lbl_kcdm = (Label)e.Item.FindControl("lbl_kcdm");
                    lbl_kcdm.ForeColor = Color.Red;
                }
                else
                {
                    Label lbl_kcdm = (Label)e.Item.FindControl("lbl_kcdm");
                    lbl_kcdm.ForeColor = Color.Black;
                }
            }
        }

        protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
        {

        }
    }
}